﻿
/// <reference path="../Pages/Config/Function.js" />


//-----------------------------------------------------------
// Author:      thuphuong.tran
// Create Date: 28/10/2010
// Description: Xử lý show popup danh sach Role
//-----------------------------------------------------------
ShowListRoleNotInFunction = new function () {
    this.functionID = 0;
    this.m_idShowListRoleNotInFunction = "divShowListRoleNotInFunction";
    this.showPopup = function (_functionID) {
        this.functionID = _functionID;
        if ($("#" + this.m_idShowListRoleNotInFunction).length == 0) {
            $("body").append("<div id='" + this.m_idShowListRoleNotInFunction + "'></div>");
            this.bindListRole();
        }

        try {
            $("#divPopup_ShowListRoleNotInFunction").draggable({ handle: $("#divPopup_ShowListRoleNotInFunction .barpopup") });
            $("#divPopup_ShowListRoleNotInFunction .barpopup").css({ cursor: 'move' });
        } catch (e) { /* requires jQuery UI draggables */ }


    };

    this.bindListRole = function () {
        $.ajax({
            type: "GET",
            url: "/Handler/HandlerConfig.ashx",
            data: { menuID: ShowListRoleNotInFunction.functionID, t: 'GetListRoleNotInMenu' },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                $("#" + ShowListRoleNotInFunction.m_idShowListRoleNotInFunction).setTemplateURL("/Template/Popup/ShowListRoleNotInMenu.htm");
                $("#" + ShowListRoleNotInFunction.m_idShowListRoleNotInFunction).processTemplate(data);
                ShowListRoleNotInFunction.setRowNumber("#" + ShowListRoleNotInFunction.m_idShowListRoleNotInFunction);
                var top = (($(window).height() / 2) - ($("#divPopup_ShowListRoleNotInFunction").outerHeight() / 2));
                var left = (($(window).width() / 2) - ($("#divPopup_ShowListRoleNotInFunction").outerWidth() / 2));
                if (top < 0) top = 0;
                if (left < 0) left = 0;
                // IE6 fix
                if ($.browser.msie && parseInt($.browser.version) <= 6) top = top + $(window).scrollTop();

                $("#divPopup_ShowListRoleNotInFunction").css({
                    top: top + 'px',
                    left: left + 'px'
                });
            }
        });
    };

    this.close = function () {
        if ($("#" + this.m_idShowListRoleNotInFunction).length != 0) {
            $("#" + this.m_idShowListRoleNotInFunction).remove();
        }
        pages_admin_Function.bindRoleInFunction();
    };

    $("#aAddRoleToFunction").live('click', function () {
        var _roleID = $(this.parentNode).attr("id").substring(3);
        var _data = {
            roleID: _roleID,
            menuID: ShowListRoleNotInFunction.functionID
        }
        $.ajax({
            type: "POST",
            url: "/WebService/WSConfig.asmx/AddRoleFunction",
            data: JSON.encode(_data),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                jAlert(MESSAGE.addSuccess, MESSAGE.title);
                ShowListRoleNotInFunction.bindListRole();
            }
        });
    });

    this.setRowNumber = function (m_selParent) {
        var m_stt = 0;
        $('#divSTT', m_selParent).each(function () {
            m_stt++;
            $(this).text(m_stt);
        });
    }

};